import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import { UploadApk } from '/@/components/UploadAPK/index';

export const columns: BasicColumn[] = [
  {
    title: '部门名称',
    dataIndex: 'name',
    width: 160,
    align: 'left',
  },
  {
    title: '排序',
    dataIndex: 'orderNo',
    width: 50,
  },
  {
    title: '是否通过',
    dataIndex: 'status',
    width: 80,
    customRender: ({ record }) => {
      const status = record.status;
      const enable = ~~status === 0;
      const color = enable ? 'green' : 'red';
      const text = enable ? '启用' : '停用';
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '原因',
    dataIndex: 'descr',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'text',
    label: '部门名称',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'status',
    label: '是否通过',
    component: 'Select',
    componentProps: {
      options: [
        { label: '启用', value: 0 },
        { label: '停用', value: 1 },
      ],
    },
    colProps: { span: 8 },
  },
];

function uploadApk(pars) {
  console.log(pars);
}

export function formSchema(uploadFileRecord: any): FormSchema[] {
  const res: FormSchema[] = [
    {
      field: 'file',
      label: 'APK',
      component: 'Input',
      required: true,
      render: ({ schema, values, model, field }) => {
        return h(UploadApk, {
          picList: [],
          maxPic: 1,
          onChange: (fileList) => {
            model[field] = fileList;
            uploadFileRecord[field] = fileList;
          },
        });
      },
    },
    {
      field: 'necessaryUpdate',
      label: '必须更新',
      component: 'Checkbox',
      defaultValue: true,
      required: true,
    },
    {
      label: '变更日志',
      field: 'changelog',
      component: 'InputTextArea',
      required: true,
    },
  ];

  return res;
}

export function formSchemaupload(uploadFileRecord: any): FormSchema[] {
  const res: FormSchema[] = [
    {
      field: 'file',
      label: '星级评判报告',
      labelWidth: 120,
      component: 'Input',
      required: true,
      render: ({ schema, values, model, field }) => {
        return h(UploadApk, {
          picList: [],
          maxPic: 1,
          onChange: (fileList) => {
            model[field] = fileList;
            uploadFileRecord[field] = fileList;
          },
        });
      },
    },
    {
      labelWidth: 120,
      label: '行政村名称',
      field: 'villageName',
      component: 'Input',
      required: true,
      componentProps: {
        disabled: true,
      },
    },
    {
      label: 'id',
      show: false,
      field: 'id',
      component: 'InputTextArea',
      required: true,
    },
  ];
  return res;
}
